<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class InitOrderUpdate extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasColumn('orders', 'activity_type')) {
            Schema::table('orders', function (Blueprint $table) {
                $table->dropColumn('activity_type');
            });
        }

        if (Schema::hasColumn('orders', 'activity_status')) {
            Schema::table('orders', function (Blueprint $table) {
                $table->dropColumn('activity_status');
            });
        }

        
        if (Schema::hasColumn('orders', 'activity_id')) {
            Schema::table('orders', function (Blueprint $table) {
                $table->dropColumn('activity_id');
            });
        }

        Schema::table('orders', function (Blueprint $table) {
            $table->string('activity_type', 20)->index()->nullable()->comment('活动类型');
            $table->tinyInteger('activity_status')->default(0)->index()->comment('0为无活动  1为活动任务进行中   2活动任务已完成   3活动任务已取消  ');
            $table->integer('activity_id')->index()->nullable()->comment('活动id');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        if (Schema::hasColumn('orders', 'activity_type')) {
            Schema::table('orders', function (Blueprint $table) {
                $table->dropColumn('activity_type');
            });
        }

        if (Schema::hasColumn('orders', 'activity_status')) {
            Schema::table('orders', function (Blueprint $table) {
                $table->dropColumn('activity_status');
            });
        }

        
        if (Schema::hasColumn('orders', 'activity_id')) {
            Schema::table('orders', function (Blueprint $table) {
                $table->dropColumn('activity_id');
            });
        }
    }
}
